package com.dean.entity;
/**
 *  异步请求返回信息处理
 * @author Administrator
 *
 */
public class DeanResponse<T> {
	/**
	 * 状态码
	 */
	private Integer code;
	/**
	 * 返回信息
	 */
	private String msg;
	/**
	 * 返回数据
	 */
	private T data;

	private static final Integer SUCESS_CODE = 0;

	private static final String SUCESS_MSG = "操作成功";

	private static final Integer ERROR_CODE = 997;

	private static final String ERROR_MSG = "未知错误";
	
	
	public Integer getCode() {
		return code;
	}
 
 
	public void setCode(Integer code) {
		this.code = code;
	}
	
	public String getMsg() {
		return msg;
	}
 
 
	public void setMsg(String msg) {
		this.msg = msg;
	}
	
	public T getData() {
		return data;
	}
 
 
	public void setData(T data) {
		this.data = data;
	}

	public DeanResponse(Integer code,String msg) {
		this.code = code;
		this.msg  = msg;
	}
	
	public DeanResponse(Integer code,String msg,T data) {
		this.code = code;
		this.msg  = msg;
		this.data = data;
	}


	/**
	 * 成功通用
	 * @return
	 */
	public static  DeanResponse  ok() {
		return ok(SUCESS_MSG,null);
	}
/*	*//**
	 * 成功通用
	 * @param <T>
	 * @param data
	 * @return
	 *//*

	*//**
	 * 成功通用
	 * @return
	 *//*
	public static  DeanResponse  ok(String msg) {
		return ok(msg,null);
	}*/

	/**
	 * 成功通用
	 * @param <T>
	 * @param data
	 * @return
	 */
	public static <T> DeanResponse<T>  ok(T data) {
		return ok(SUCESS_MSG,data);
	}


	/**
	 *
	 * @param msg
	 * @param data
	 * @param <T>
	 * @return
	 */
	public static <T> DeanResponse<T>  ok(String msg,T data) {
		return new DeanResponse<T>(SUCESS_CODE, msg,data);

	}



	
	/**
	 * 设置返回数据
	 * @param <T>
	 * @param code
	 * @param msg
	 * @param data
	 * @return
	 */
	public static <T> DeanResponse<T>  build(Integer code,String msg,T data) {
		return new DeanResponse<T>(code, msg,data);
	}

	/**
	 * 设置返回数据
	 * @param <T>
	 * @param code
	 * @param msg
	 * @return
	 */
	public static <T> DeanResponse<T>  build(Integer code,String msg) {
		return build(code, msg,null);
	}


	/**
	 * 返回错误信息
	 * @return
	 */
	public static DeanResponse error(){
		return error(ERROR_CODE,ERROR_MSG);
	}
	/**
	 * 返回错误信息
	 * @param msg   错误信息
	 * @return
	 */
	public static DeanResponse error(String msg){
		return error(ERROR_CODE,msg);
	}

	/**
	 * 返回错误信息
	 * @param code  错误代码
	 * @param msg   错误信息
	 * @return
	 */
	public static DeanResponse error(Integer code,String msg){
		return error(code, msg,null);
	}

	/**
	 * 返回错误信息
	 * @param <T>
	 * @param code  错误代码
	 * @param msg   错误信息
	 * @return
	 */
	public static <T> DeanResponse<T>  error(Integer code,String msg,T data){
		return new DeanResponse<T>(code, msg,data);
	}

	@Override
	public String toString() {
		return "DeanResponse{" +
				"code=" + code +
				", msg='" + msg + '\'' +
				", data=" + data +
				'}';
	}
}
